package com.vaadin.incubator.bugrap.model.facade;

import java.util.HashMap;
import java.util.Map;

public class FacadeFactory {

	private static Map<String, IFacade> facades = new HashMap<String, IFacade>();

	private static IFacade defaultFacade;

	public static void registerFacade(String name, boolean isDefault) {
		registerFacade(name, isDefault, null);
	}

	public static void registerFacade(String name, boolean isDefault,
			Map<String, Object> options) {
		if (facades.containsKey(name)) {
			facades.get(name).close();
		}

		FacadeImpl facade = new FacadeImpl(name, options);
		facades.put(name, facade);

		if (isDefault) {
			defaultFacade = facade;
		}
	}

	public static IFacade getFacade() {
		return defaultFacade;
	}

	public static IFacade getFacade(String name) {
		return facades.get(name);
	}

	public static void removeFacade(String name) {
		if (facades.containsKey(name)) {
			IFacade facade = facades.get(name);
			facade.kill();
			facades.remove(name);
		}
	}

}
